var tablename = "video";
var app = this;
var $ = require("../../include/$");
module.exports = {
	get: function (req, res) {
		req.models["course"].get(req.query.cid, function (err, course) {
			if (err) {
				res.send(500, err);
			} else {
				req.models[tablename].get(req.query.id, function (err, result) {
					if (err) {
						res.send(500, err);
					} else {
						if (req.query.uid == course.tid) {
							res.send(result);
							res.end();
						} else {
							var _array = eval(course.sid);
							for (var i = 0; i < _array.length; i++) {
								if (_array[i] == req.query.uid) {
									res.send(result);
									res.end();
								}
							};
							res.end();
						}
					};
				});
			}
		});
	},
	put: function (req, res) {
		req.models[tablename].get(req.body.vid, function (err, result) {
			if (err) {
				res.send(500, err);
			} else {
				var _array = eval(result.chat);
				_array.push(req.body.msg);
				result.chat = JSON.stringify(_array);
				result.save(function (err) {
					if (err) {
						res.send(500, err);
					};
				});
			};
		});
	}
}